import {
    Base
} from '../../utils/base.js'

class Product extends Base {
    constructor() {
        super()
    }
    //获取商品详细信息
    getGoodsById(parames, callback) {
        let url = "/ddaigo-platform/goods/getGoodsById";
        this.commonRequest(url, parames, callback);
    }
    //添加商品进购物车
    addCart(parames, callback) {
        let url = "/ddaigo-platform/cart/add";
        this.commonRequest(url, parames, callback);
    }

    //获取购物车总数
    getCart(parames, callback) {
        let url = "/ddaigo-platform/cart/get";
        this.commonRequest(url, parames, callback);
    }

    // 创建订单
    createOrderAndDetails(parames, callback) {
        let url = '/ddaigo-platform/order/createOrderAndDetails';
        this.commonRequest(url, parames, callback);
    }
    // 立即抢购
    nowBuy(parames, callback) {
        let url = '/ddaigo-platform/order/createOrderAndDetailsRightNow';
        this.commonRequest(url, parames, callback);
    }
    // 绑定邀请码
    bindInviteCodeByMiniProgram(parames, callback) {
        let url = '/ddaigo-platform/code/bindInviteCodeByMiniProgram';
        this.commonRequest(url, parames, callback);
    }
    //定时器处理
    countdown(endtime) {
        var date = new Date();
        var end = new Date(endtime);
        var _time = end - date;
        if (_time <= 0 || !endtime) return {
            hour: '00',
            minute: '00',
            second: '00'
        }
        var d = Math.floor(_time / 1000 / 60 / 60 / 24);
        var h = Math.floor(_time / 1000 / 60 / 60 % 24);
        var m = Math.floor(_time / 1000 / 60 % 60);
        var s = Math.floor(_time / 1000 % 60);
        var ms = Math.floor(_time % 1000);
        if (h < 10) h = '0' + h
        if (m < 10) m = '0' + m
        if (s < 10) s = '0' + s
        return {
            hour: h,
            minute: m,
            second: s
        }
        // console.log(`${d}天${h}小时${m}分${s}秒${ms}`)
    }
}
module.exports = {
    Product
}